var unit = {
  getUrlParam: function () {
    var url = window.location.href
  }
}

$('#header').load('../../../views/Common/header.html', function () {
  initTopbar()
  $('.navigation li').eq(pageindex).addClass('active')
})
$('#footer').load('../../../views/Common/footer.html', function () {
  // 浮窗
  $(document).on('click', '.js_close', function () {
    $(this).parent('.fixed-qr').hide();
  })

})

function isLogin(href) {
  if (document.cookie.length <= 1) {
    window.location.href = "../Login/login.html";
  } else {
    window.location.href = href;
  }
}


function singout() {
  deleteallcookie();
  $.post('/Login/SignOut');
  window.location.href = "../Home/Index.html"
}

function cancel() {
  window.history.go(-1)
}

function deleteallcookie() {
  var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
  if (keys) {
    for (var i = keys.length; i--;) {
      document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString() + ";path=/";
    }
  }
}

function initTopbar() {
  var logionhref = "../Home/Index.html";
  if (document.cookie.length > 0) {
    $('#login_yes').show();
    $('#login_no').hide();
  }
  ///获取cookie
  var c_name = "value"; // 变量名
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=")
    if (c_start != -1) {
      c_start = c_start + c_name.length + 1
      c_end = document.cookie.indexOf(";", c_start);
      if (c_end == -1) c_end = document.cookie.length
      var sss = unescape(document.cookie.substring(c_start, c_end)) // 取出值
      $("#username").html(sss + " 您好！");
      if ($("#username").text() == "") {
        $('#login_yes').hide();
      } else {
        $('#login_no').hide();
      }
    }
  }

  try {
    if (document.cookie && document.cookie.split(";")[2].split("=")[1] == 1) {
      $("#grid_work").show();
      $("#grid_work2").show();
    } else {
      $("#grid_work").hide();
      $("#grid_work2").hide();
    }
  } catch (e) {
    $("#grid_work").hide();
    $("#grid_work2").hide();
  }


  var today = new Date(),
    year = today.getFullYear(),
    month = today.getMonth() + 1,
    day = today.getDate(),
    week = today.getDay(),
    weekArr = ['天', '一', '二', '三', '四', '五', '六']
  result = year + '年' + month + '月' + day + '日' + '星期' + weekArr[week]
  $('#today').text(result)
}

///邮箱格式验证
function isCheckEmail(str) {
  var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  if (!myreg.test(str)) {
    return false;
  } else {
    return true;
  }
}


initTopbar()